/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this
work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the
"License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * *
http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is
distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific
language governing permissions and * limitations under the License. */
<template>
  <m-list-construction title="机主申请">
    <template slot="operation">
      <el-button
        type="primary"
        size="mini"
        @click="_create()"
      >机主申请</el-button>
      <!-- mCheck  -->
      <el-dialog
        title="申请单审核"
        :visible.sync="createDialog"
        width="auto"
        append-to-body
      >
        <mCheck
          :item="item"
          @onUpdate="onUpdate"
          @close="close"
        ></mCheck>
      </el-dialog>
    </template>
    <template slot="conditions">
      <topCondition @on-conditions="_onConditions"></topCondition>
    </template>
    <template slot="content">
      <template v-if="routeList.length || total > 0">
        <m-list
          @on-check="_onCheck"
          :environment-list="routeList"
          :page-no="searchParams.pageNum"
          :page-size="searchParams.pageSize"
        > </m-list>
        <div class="page-box">
          <el-pagination
            background
            @current-change="_page"
            @size-change="_pageSize"
            :page-size="searchParams.pageSize"
            :current-page.sync="searchParams.pageNum"
            :page-sizes="[10, 30, 50]"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </template>
      <template v-if="!routeList.length && total <= 0">
        <m-no-data></m-no-data>
      </template>
      <m-spin
        :is-spin="isLoading"
        :is-left="isLeft"
      ></m-spin>
    </template>
  </m-list-construction>
</template>
<script>
  import _ from 'lodash'
  import { mapActions } from 'vuex'
  import mList from './components/list.vue'
  // import store from '@/conf/home/store'
  import mSpin from '@/module/components/spin/spin'
  import mCheck from './components/check.vue'
  import mNoData from '@/module/components/noData/noData'
  import listUrlParamHandle from '@/module/mixin/listUrlParamHandle'
  import topCondition from './components/topCondition.vue'
  import mListConstruction from '@/module/components/listConstruction/listConstruction'

  export default {
    name: 'application-index',
    data () {
      return {
        total: null,
        isLoading: true,
        routeList: [
          {
            id: 1,
            name: '柏林',
            tel: '15219491691',
            company: '研究院',
            applicationType: '个人',
            count: 2,
            creatTime: '2023-08-25',
            updateTime: '2023-08-25',
            status: 2
          },
          {
            id: 1,
            name: '柏林',
            tel: '15219491691',
            company: '研究院',
            applicationType: '企业',
            count: 2,
            creatTime: '2023-08-25',
            updateTime: '2023-08-25',
            status: 2
          }
        ],
        searchParams: {
          pageSize: 10,
          pageNum: 1,
          type: 0,
          searchVal: ''
        },
        isLeft: true,
        item: {},
        createDialog: false,
      }
    },
    mixins: [listUrlParamHandle],
    props: {},
    methods: {
      ...mapActions('network', ['getNetworkListPaging']),
      /**
       * Query
       */
      _onConditions (o) {
        this.searchParams = _.assign(this.searchParams, o)
        this.searchParams.pageNum = 1
        console.log('this.searchParams', this.searchParams)
      },
      _page (val) {
        this.searchParams.pageNum = val
      },
      _pageSize (val) {
        this.searchParams.pageSize = val
      },
      _onCheck (item) {
        this.item = item
        this.createDialog = true
      },
      _create () {
        // 点击机主申请跳转页面
        this.$router.push({ path: '/equipment/application/ownerApplication' })
      },
      onUpdate () {
        this._debounceGET('false')
        this.createDialog = false
      },
      close () {
        this.createDialog = false
      },
      _getList (flag) {
        if (sessionStorage.getItem('isLeft') === 0) {
          this.isLeft = false
        } else {
          this.isLeft = true
        }
        this.isLoading = !flag
        Promise.all([this.getNetworkListPaging({ ...this.searchParams, name: this.searchParams.searchVal })])
          .then((values) => {
            console.log('fdasfas', values)
            if (this.searchParams.pageNum > 1 && values[0].rows.length === 0) {
              this.searchParams.pageNum = this.searchParams.pageNum - 1
            } else {
              this.routeList = []
              this.routeList = [
                {
                  id: 1,
                  name: '柏林',
                  tel: '15219491691',
                  company: '研究院',
                  applicationType: '个人',
                  count: 2,
                  creatTime: '2023-08-25',
                  updateTime: '2023-08-25',
                  status: 2
                },
                {
                  id: 1,
                  name: '柏林',
                  tel: '15219491691',
                  company: '研究院',
                  applicationType: '企业',
                  count: 2,
                  creatTime: '2023-08-25',
                  updateTime: '2023-08-25',
                  status: 2
                }
              ]
              this.total = values[0].total
              this.isLoading = false
            }
          })
          .catch((e) => {
            this.isLoading = false
          })
      },
    },
    // beforeDestroy () {
    //   sessionStorage.setItem('isLeft', 1)
    // },
    components: { mList, mListConstruction, mSpin, mNoData, mCheck, topCondition },
  }
</script>
